package com.medicine.controller;

import java.io.IOException;
import java.sql.Date;
import java.sql.Timestamp;
import java.util.HashMap;
import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import net.sf.json.JSON;
import net.sf.json.JSONArray;
import net.sf.json.JSONObject;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import pagination.Page;
import po.Ypkcxx;
import po.Ypxx;
import requestvo.SupplierReqVo;
import requestvo.YpkcxxReqVo;

import com.google.gson.JsonObject;
import com.medicine.dao.impl.SupplierDao;
import com.medicine.dao.impl.YpkcxxDao;
import com.medicine.dao.impl.RkxxDao;

@Controller
public class SupplierController extends BaseController {
	@RequestMapping("/gysxx")
	public void findGys(SupplierReqVo supplierReqVo,
			HttpServletResponse response) throws IOException {
		Page<SupplierReqVo> page = supplierService.findsupplierxx(supplierReqVo);
		JSONObject jsonObject = new JSONObject();
		jsonObject.element("rows", page.getResults());
		jsonObject.element("total", page.getTotalRecord());
		response.setCharacterEncoding("UTF-8");
		response.setContentType("application/json; charset=utf-8");
		response.getWriter().print(jsonObject.toString());

	}

	@RequestMapping("/updategysxx")
	public void updateGys(SupplierReqVo supplierReqVo,
			HttpServletResponse response) throws IOException {
		supplierService.updategysxx(supplierReqVo);
		response.sendRedirect("supplier.html");
	}

	@RequestMapping("/addgysxx")
	public void addGys(SupplierReqVo supplierReqVo, HttpServletResponse response)
			throws IOException {

		supplierService.addgysxx(supplierReqVo);
		response.sendRedirect("supplierReqVo.html");
	}

	@RequestMapping("/delgysxx")
	public void delGys(String ids, HttpServletResponse response)
			throws IOException {
		String[] id = ids.split(",");
		System.out.println(id.length);
		String[] integers = new String[id.length];
		for (int i = 0; i < id.length; ++i)
			integers[i] = id[i];
		supplierService.delgysxx(integers);
		response.sendRedirect("supplierReqVo.html");
	}
	/*
	 * @RequestMapping("/checkgysxx") public void checkYPBM(Integer
	 * gysbm,HttpServletResponse response) throws IOException{ SupplierReqVo
	 * supplierReqVo=supplierDao.get(gysbm); if(supplierReqVo==null)
	 * response.getWriter().print(""); else response.getWriter().print("live");
	 * }
	 */
	/*
	 * @RequestMapping("/findAllYpxx") public void
	 * findAllYpxx(HttpServletResponse response) throws IOException{
	 * 
	 * response.setCharacterEncoding("UTF-8");
	 * response.setContentType("application/json; charset=utf-8"); JsonObject
	 * jsonObject=new JsonObject(); JSONArray
	 * jsonArray=JSONArray.fromObject(ypkcxxService.findAll());
	 * response.getWriter().print(jsonArray.toString()); }
	 */
}
